home *** CD-ROM | disk | FTP | other *** search
- /*
- DAC Palette Example. For VGA cards only.
-
- Copyright (c) 1994 Jeffrey C. Moxon CIS: 73561,1431
-
- Adapted from 'PC Intern' by Michael Tischer
-
- Provides three example functions to set the palette.
-
- 1. The assembly routines: setdac() and getdac()
- 2. The C Interrupt based routines: csetdac() and cgetdac()
- 3. The C VGA DAC register routines: csetreg() and cgetreg()
-
- This routine will work in either graphics mode, or in text mode.
-
- */
-
- #include <conio.h>
- #include <dos.h>
- #include <graphics.h> /* For detection routine */
- #include <stdio.h>
-
- union dac
- {
- struct
- {
- char Red; /* Red portion of color 0..63 */
- char Green; /* Green portion of color 0..63 */
- char Blue; /* Blue portion of color 0..63 */
- } color;
- char RGB[3];
- };
-
- /*
- Declaration for assembly routines.
- Uncomment declarations and replace all calls to csetdac with
- setdac, and all calls to cgetdac with getdac.
- Compile and link with: BCC _dac.c, dac.asm
- */
-
- extern void far getdac(int start, int number, union dac far *dac_block);
- extern void far setdac(int start, int number, union dac far *dac_block);
- extern void far setborder(unsigned char color);
- extern void far setvideomode(unsigned char mode);
-
- /*
- These two functions change the DACs using interrupt 0x10
- */
-
- void csetdac(int start, int number, union dac *dac_block);
- void cgetdac(int start, int num, union dac *dac_block);
-
- /*
- These two functions are the same as the assembly routines,
- except written in C. Replace all calls to csetdac with csetreg,
- and all calls to cgetdac with cgetreg.
- */
-
- void csetreg(int start, int number, union dac *dac_block);
- void cgetreg(int start, int num, union dac *dac_block);
-
-
- void csetborder(unsigned char color);
-
- /* See if VGA card present */
- int detect_VGA(void);
-
- void main(void)
- {
- union dac my_block[16]; /* Variable to hold first 16 colors */
- int x, y; /* Index variables */
- int key = 0;
-
-
- /* Check for VGA */
- if (!detect_VGA())
- {
- printf("Requires VGA card.\n");
- return;
- }
-
-
- clrscr();
-
- /* Fill the screen with characters */
- for (y = 1; y < 26; y++)
- for (x = 1; x < 80; x++)
- {
- gotoxy(x,y);
- cprintf("%c", y + 'A');
- }
-
- /* Fade from black to red */
- for(y = 0; y < 63; y++)
- {
- my_block[BLACK].RGB[0] = y;
- my_block[BLACK].RGB[1] = 0;
- my_block[BLACK].RGB[2] = 0;
- csetdac(0, 1, my_block);
- delay(20);
- }
-
- /* Reset black color */
- my_block[BLACK].RGB[0] = 0;
- csetdac(0, 1, my_block);
-
- /* Fade from black to green */
- for(y = 0; y < 63; y++)
- {
- my_block[BLACK].RGB[0] = 0;
- my_block[BLACK].RGB[1] = y;
- my_block[BLACK].RGB[2] = 0;
- csetdac(0, 1, my_block);
- delay(20);
- }
-
- /* Reset black color */
- my_block[BLACK].RGB[1] = 0;
- csetdac(0, 1, my_block);
-
-
- /* Fade from black to blue */
- for(y = 0; y < 63; y++)
- {
- my_block[BLACK].RGB[0] = 0;
- my_block[BLACK].RGB[1] = 0;
- my_block[BLACK].RGB[2] = y;
- csetdac(0, 1, my_block);
- delay(20);
- }
-
-
- /* Reset black color */
- my_block[BLACK].RGB[2] = 0;
- csetdac(0, 1, my_block);
-
- textcolor(RED);
-
- /* Turn on border */
- csetborder(RED);
-
- gotoxy(17,13);
- cprintf("Watch the RED as you hit keys, Press ESC to exit.");
-
-
- /* Read in all 16 active DAC registers */
- cgetdac(0, 16, my_block);
-
- x = 0;
-
- while(key != 27) /* 27 is ESC */
- {
- key = getch();
-
- /* change red block to each color as key is pressed */
- csetdac(RED, 1, &my_block[x]);
- if (x > 15) x = 0;
- x++;
- }
-
-
-
- /* Reset all values by changing video mode */
- asm mov ah, 0;
- asm mov al, 0x03; /* Mode in al */
- asm int 0x10;
-
- return;
- }
-
- /*
- Set a block of DAC registers using interrupt 0x10. This routine produces
- large amounts of screen flicker, and therefore should be written in ASM
- with a wait for vertical retrace prior to executing the int.
- */
-
- void csetdac(int start, int number, union dac *dac_block)
- {
- union REGS r;
- struct SREGS s;
-
- s.es = FP_SEG(dac_block); //dac_block is a pointer to DAC structure
- r.x.dx = FP_OFF(dac_block);
-
- r.x.ax = 0x1012; //Function 1012 is set block of DAC registers
- r.x.bx = start; //BX holds number to begin with (0 to 255)
- r.x.cx = number; //CX holds how many to set
- int86x(0x10, &r, &r, &s);
-
- return;
- }
-
- /* Read block of DAC registers from start to number using int 0x10 */
- void cgetdac(int start, int number, union dac *dac_block)
- {
- union REGS r;
- struct SREGS s;
-
- s.es = FP_SEG(dac_block);
- r.x.dx = FP_OFF(dac_block);
-
- r.x.ax = 0x1017;
- r.x.bx = start;
- r.x.cx = number;
- int86x(0x10, &r, &r, &s);
-
- return;
- }
-
- /* Set Overscan color to produce border */
- void csetborder(unsigned char color)
- {
- union REGS r;
-
- r.x.ax = 0x1001;
- r.h.bh = color;
- int86(0x10, &r, &r);
-
- return;
- }
-
- /* Set DAC's without using interrupt */
- void csetreg(int start, int number, union dac *dac_block)
- {
- int i;
-
- outp(0x3c6,0xff);
- outp(0x3c8, start);
- for(i=0;i<number;i++)
- {
- outp(0x3c9, dac_block->RGB[0]); /* Red */
- outp(0x3c9, dac_block->RGB[1]); /* Green */
- outp(0x3c9, dac_block->RGB[2]); /* Blue */
- dac_block++;
- }
-
- return;
- }
-
- /* Get DAC's without using interrrupt */
- void cgetreg(int start, int number, union dac *dac_block)
- {
- int i;
-
- outp(0x3c7, start);
- for(i=0;i<number;i++)
- {
- dac_block->RGB[0] = inp(0x3c9); /* Red */
- dac_block->RGB[1] = inp(0x3c9); /* Green */
- dac_block->RGB[2] = inp(0x3c9); /* Blue */
- dac_block++;
- }
-
- return;
- }
-
- int detect_VGA(void)
- {
- int g_driver, g_mode;
-
- g_driver = DETECT;
-
- detectgraph(&g_driver, &g_mode);
-
- if (g_driver != VGA) return(0);
-
- return(1);
- }
-